//
//  SearchProjectInfoVC.m
//  HappyStore
//
//  Created by 李小辉 on 16/5/25.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "SearchProjectInfoVC.h"
#import "SerachProjectFirView.h"
#import "PinLunCell.h"
#import "PinLunVC.h"
#import "recommendViC.h"
#import "goveDetailVC.h"
#import "thirdPersonVC.h"
#import "ProjectPublisherView.h"
#import "WriteComment.h"

static NSInteger page;

static NSInteger count;

@interface SearchProjectInfoVC ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong,nonatomic) NSString *isFocus;//判断关注非关注
@property (strong, nonatomic) SerachProjectFirView *projectFir; // 中段界面
@property (strong, nonatomic) ProjectPublisherView *publisherView;//项目发布人
@property (strong, nonatomic) UITableView *tableview;
@property (strong, nonatomic) UILabel * topTitle;

@property (strong, nonatomic) NSMutableArray *positionArr;
@property (strong, nonatomic) NSMutableArray *createTimeArr;

@property (strong, nonatomic) IBOutlet UIButton *collectionBtn;

@property (strong, nonatomic) NSMutableArray *commentsList;

@property (strong, nonatomic) recommendViC * recommendview;


@end

@implementation SearchProjectInfoVC
#pragma mark - 初始化


- (ProjectPublisherView *)publisherView{
    if (!_publisherView) {
        _publisherView = [[[NSBundle mainBundle] loadNibNamed:@"ProjectPublisherView" owner:self options:nil] lastObject];
    }
    return _publisherView;
}

-(NSMutableArray *)commentsList{
    if (!_commentsList) {
        _commentsList = [NSMutableArray array];
    }
    return _commentsList;
}

-(SerachProjectFirView *)projectFir{
    if (!_projectFir) {
        _projectFir = [[[NSBundle mainBundle] loadNibNamed:@"SerachProjectFirView" owner:self options:nil] lastObject];
    }
    return _projectFir;
}

-(recommendViC *)recommendview{
    if (!_recommendview) {
        _recommendview = [[recommendViC alloc]init];
    }
    return _recommendview;
}
-(NSMutableArray *)projectData{
    if (!_projectData) {
        _projectData = [NSMutableArray array];
    }
    return _projectData;
}
-(NSMutableArray *)positionArr{
    if (!_positionArr) {
        _positionArr = [NSMutableArray array];
    }
    return _positionArr;
}
-(NSMutableArray *)createTimeArr{
    if (!_createTimeArr) {
        _createTimeArr = [NSMutableArray array];
    }
    return _createTimeArr;
}
-(NSDictionary *)dataDict{
    if (!_dataDict) {
        _dataDict = [NSDictionary dictionary];
    }
    return _dataDict;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = NO;
    //导航条都透明度
    self.navigationController.navigationBar.translucent = NO;
    
    self.tabBarController.tabBar.hidden = YES;
    count = 1;
    if (self.projectData.count == 10) {
        self.scrollView.mj_footer.hidden = NO;
    }else{
        self.scrollView.mj_footer.hidden = YES;
    }
    
    self.isFocus = _dataDict[@"isfocus"];
    if ([self.isFocus isEqualToString:@"是"]) {
        [self.collectionBtn setImage:[UIImage imageNamed:@"评论点赞图标"] forState:UIControlStateNormal];
    }else{
        [self.collectionBtn setImage:[UIImage imageNamed:@"资讯-点赞"] forState:UIControlStateNormal];
    }

    // 设置toptitle
    [self setupTopTitle];
    
    
    
    //设置基础数据
    [self setupProjectFir];
    
    [self.tableview reloadData];
    
    // 加载评论
    //[self sendProjectRequest];
    
    if ([self.tig isEqualToString:@"project"]) {
        self.publisherView.jumpButton.hidden = YES;
    }
    
   
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    //导航条都透明度
    self.navigationController.navigationBar.translucent = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"项目详情";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;


    self.projectId = self.dataDict[@"projectId"];
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
//    UIBarButtonItem *rightItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBarButtonItemClick) image:@"Share-Icon" highImage:@"Share-Icon"];
//    self.navigationItem.rightBarButtonItem = rightItem;
    
    // 监听点击
    [self.recommendview.recommendView.sureBtn addTarget:self action:@selector(sureBtn) forControlEvents:UIControlEventTouchUpInside];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePinlun:) name:@"updatePinlun" object:nil];
    page = 1;
    
    self.view.width = screenW;
    [self.scrollView setFrame:CGRectMake(0, 64, screenW, screenH - 50 - 64)];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

}
- (void)updatePinlun: (NSNotification *)noti{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    if ([dic[@"result"] integerValue] == 1) {
        page = 1;
        self.projectData = nil;
        [self sendProjectRequest];
    }
}
-(void)setupDownRefresh{
    
    self.scrollView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        page++;
        [self sendProjectRequest];
    }];
}
#pragma mark - 点击个人跳转
-(void)goGoveBy{
    if ([_dataDict[@"userType"] integerValue] == 3) {
        goveDetailVC * goveVC = [[goveDetailVC alloc]init];
        goveVC.userId = _dataDict[@"userId"];
        goveVC.userType = _dataDict[@"userType"];
        [self.navigationController pushViewController:goveVC animated:YES];
    }else{
        thirdPersonVC *thirdVC = [[thirdPersonVC alloc] init];
        thirdVC.userId = _dataDict[@"userId"];
        thirdVC.userType = _dataDict[@"userType"];
        [self.navigationController pushViewController:thirdVC animated:YES];
    }
}
-(void)sureBtn{
    
    if (self.recommendview.recommendView.nameTextField.text.length < 1 || self.recommendview.recommendView.phoneTextField.text.length < 1) {

        [self showSingleIconBubble:@"请完善内容"];
        
    }else{
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        dic[@"resId"] = self.projectId;
        dic[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
        dic[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
        dic[@"type"] = @(1);
        dic[@"touchName"] = self.recommendview.recommendView.nameTextField.text;
        dic[@"touchWay"] = self.recommendview.recommendView.phoneTextField.text;
        
        [LSHttpTool sendHttpData:@"referralplatform_app_project.im.lensum" params:dic success:^(id responseObject) {
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"平台引荐成功！工作人员将在三日之内给您答复！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
            
        } failure:^(NSError *error) {

           [self showSingleIconBubble:@"网络连接错误"];
            
        }];
        
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    [self.recommendview dismissViewControllerAnimated:YES completion:nil];
}

- (void)rightBarButtonItemClick{
    //http://m.lensum.com/xm_detail.php?id=1
    NSString *urlstr = [NSString stringWithFormat:@"http://m.lensum.com/xm_detail.php?id=%@",self.projectId];
    NSString *contentStr = @"";
    if ([_dataDict[@"description"] length] >= 50) {
        contentStr = [_dataDict[@"description"] substringToIndex:50];
    }else{
        contentStr = _dataDict[@"description"];
    }
    
    [ShareMsg shareMsgBOOLType:NO titleStr:_dataDict[@"title"] contentStr:contentStr urlStr:urlstr imageAry:nil];

}
-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setupTopTitle{
    UILabel *toptitle = [[UILabel alloc]init];
    toptitle.text = _dataDict[@"title"];
    toptitle.numberOfLines = 0;
    toptitle.lineBreakMode = NSLineBreakByWordWrapping;
    toptitle.backgroundColor = [UIColor whiteColor];
    
    toptitle.textColor = RGB(0, 0, 0);
    toptitle.textAlignment = NSTextAlignmentCenter;
    UIFont *font = [UIFont systemFontOfSize:20.0f];
    toptitle.font = font;
    CGSize constraint = CGSizeMake(screenW, 2000.0f);
    
    CGSize size = [toptitle sizeThatFits:constraint];
    [toptitle setFrame:CGRectMake(0, -1, screenW, size.height + 40)];
    self.topTitle = toptitle;
    [_scrollView addSubview:self.topTitle];
    
}


#pragma mark - 布局中段

-(void)setupProjectFir{
    
    if (!self.userId) {
        [self.publisherView.headPhotoImageView sd_setImageWithURL:[NSURL URLWithString:self.dataDict[@"headPhoto"]]];
        if ([self.dataDict[@"username"] isEqualToString:@""]||[self.dataDict[@"username"] isEqualToString:@"null"]) {
            self.publisherView.userName.text = self.dataDict[@"account"];
        }else{
            self.publisherView.userName.text = self.dataDict[@"username"];
        }
        
        if (self.dataDict[@"posiTionName"]==nil||[self.dataDict[@"posiTionName"] isEqualToString:@"null"]) {
            self.publisherView.positionName.text = @"";
        }else{
            self.publisherView.positionName.text = self.dataDict[@"posiTionName"];
        }
        //认证
        self.publisherView.isAuthState.hidden = [UsedTool authStateImageViewHidden:self.dataDict[@"authState"]];
        //会员图标
        self.publisherView.authStateImageView.image = [UsedTool setVipimage:self.dataDict[@"vipLevel"]];
        
        
        
        //封装判断好的上级
        self.publisherView.addressLabel.text = [UsedTool userType:self.dataDict[@"userType"] companyName:self.dataDict[@"companyName"] userAddress:self.dataDict[@"userAddress"]];
        [self.publisherView.jumpButton addTarget:self action:@selector(goGoveBy) forControlEvents:UIControlEventTouchUpInside];
        self.publisherView.frame = CGRectMake(0, self.topTitle.height, screenW, 105);
        [self.scrollView addSubview:self.publisherView];
        
    }
    
    self.projectFir.descriptionLabel.text = _dataDict[@"description"];
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.projectFir.descriptionLabel.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [self.projectFir.descriptionLabel.text length])];
    [self.projectFir.descriptionLabel setAttributedText:attributedString1];
    [self.projectFir.descriptionLabel sizeToFit];
    
    self.projectFir.descriptionLabel.textAlignment = NSTextAlignmentLeft;
    
    CGSize constraint = CGSizeMake(screenW - 20, MAXFLOAT);
    CGSize size = [self.projectFir.descriptionLabel sizeThatFits:constraint];
    
    
    if (!self.userId) {
        self.projectFir.frame = CGRectMake(0, self.publisherView.y + self.publisherView.height, screenW, self.projectFir.descriptionLabel.y + size.height + 100);
    }else{
        self.projectFir.frame = CGRectMake(0, self.topTitle.height, screenW, self.projectFir.descriptionLabel.y + size.height + 100);
    }
    
    self.projectFir.industry.text = _dataDict[@"qualityName"];
    self.projectFir.address.text = _dataDict[@"address"];
    
    if ([[self comperNumber:_dataDict[@"investment"]] isEqualToString:@"0.00元"]) {
        self.projectFir.investment.text = @"面议";
    }else{
        self.projectFir.investment.text = [self comperNumber:_dataDict[@"investment"]];
    }
    
    [self.scrollView addSubview:self.projectFir];
    [self.projectFir.clickBtn addTarget:self action:@selector(downButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.scrollView.contentSize = CGSizeMake(screenW, self.projectFir.y + self.projectFir.height);
    [self setupTableView];
    
    
    
}






-(void)setupTableView{
    UITableView *tableview = [[UITableView alloc]init];
    tableview.x = 0 ;
    tableview.y = self.projectFir.y + self.projectFir.height;
    tableview.width = screenW;
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.showsVerticalScrollIndicator = NO;
    tableview.showsHorizontalScrollIndicator = NO;
    tableview.scrollEnabled = NO;
    [self.scrollView addSubview:tableview];
    
    self.tableview = tableview;
    //去掉自定义cell底部的黑线
    self.tableview.separatorStyle = UITableViewCellSelectionStyleNone;
    // 集成下拉加载更多
    [self setupDownRefresh];
    
    [self.tableview reloadData];
    
}


#pragma mark - 控件方法
// 平台引荐
- (IBAction)recommendBtn:(UIButton *)sender {

    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
       
        self.recommendview.modalPresentationStyle=UIModalPresentationOverCurrentContext;
        [self presentViewController:self.recommendview animated:YES completion:nil];

    }else{
        [SVProgressHUD showErrorWithStatus:@"请先登录!"];
        [SVProgressHUD dismissafterDelay:kHideHudDelay];
                
    }
}
// 分享
- (IBAction)shareBtn:(UIButton *)sender {
    //http://m.lensum.com/xm_detail.php?id=1
    NSString *urlstr = [NSString stringWithFormat:@"http://m.lensum.com/xm_detail.php?id=%@",self.projectId];
    NSString *contentStr = @"";
    //去除特殊字符
    contentStr = [ChineseString RemoveSpecialCharacter:_dataDict[@"description"]];
    //去除“回车”字符
    NSString *strContent = [contentStr stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
        if ([strContent length] >= 50) {
            contentStr = [strContent substringToIndex:50];
        }else{
            contentStr = strContent;
        }
    [ShareMsg shareMsgBOOLType:NO titleStr:_dataDict[@"title"] contentStr:contentStr urlStr:urlstr imageAry:nil];
    
}
/**
 *
 *  提交评论
 */

- (IBAction)commentBtn:(UIButton *)sender {
//    page = 1;
//    PinLunVC * pVC = [[PinLunVC alloc]init];
//    pVC.resId = self.dataDict[@"projectId"];
//    pVC.str = @"commentProject_app_action.im.lensum";
//    [self.navigationController pushViewController:pVC animated:YES];

//    //成为第一响应者
//    [textContentTextField becomeFirstResponder];
    WriteComment *writeView = [[WriteComment alloc] init];
    [writeView setFrame:CGRectMake(0, self.view.frame.size.height - 48, screenW, 48)];
    writeView.resId = self.dataDict[@"projectId"];
    writeView.urlStr = @"commentProject_app_action.im.lensum";
    [self.view addSubview:writeView];
}
// 关注
- (IBAction)collectionBtn:(UIButton *)sender {
    
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        dic[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
        dic[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
        dic[@"resId"] = self.projectId;
        dic[@"resType"] = @(1);
        
        NSString *strURL = @"";
        if ([self.isFocus isEqualToString:@"否"]) {
            strURL = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResources_app_action.im.lensum"];
            
        }else{
            strURL = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResourcesCancel_app_action.im.lensum"];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURL parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
            //NSLog(@"dicINFO:%@",dicInfo);
            if ([dicInfo[@"result"] integerValue] == 1) {
                if ([self.isFocus isEqualToString:@"否"]) {
                    //[self.btnCollect setImage:[UIImage imageNamed:@"yishouchang_11"] forState:UIControlStateNormal];
                    [self.collectionBtn setImage:[UIImage imageNamed:@"评论点赞图标"] forState:UIControlStateNormal];
                    self.isFocus = @"是";
                }else{
                    [self.collectionBtn setImage:[UIImage imageNamed:@"资讯-点赞"] forState:UIControlStateNormal];
                    self.isFocus =@"否";
                }

            }
            if ([dicInfo[@"result"] integerValue] == 2) {
                if ([self.isFocus isEqualToString:@"否"] ) {
                    self.isFocus =@"否";
                }else{
                    self.isFocus = @"是";
                }

            }

            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:@"网络连接错误"];

        }];
        
        
        
    }else{
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
    
    

}

#pragma mark - tableview datasource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.projectData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"-----------------%@",self.positionArr);
    // 注册
    static NSString *pinlun = @"pinlunCell";
    UINib * nib = [UINib nibWithNibName:@"PinLunCell" bundle:nil];
    [self.tableview registerNib:nib forCellReuseIdentifier:pinlun];
    
    PinLunCell * cell = [self.tableview dequeueReusableCellWithIdentifier:pinlun];
    if (!cell) {
        cell = [[PinLunCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pinlun];
    }
    
    
    
    NSDictionary *dict = self.projectData[indexPath.row];
    //职位 个人才有
    if ([dict[@"userType"] integerValue] == 1) {
        if ([dict[@"posiTion"] isEqualToString:@"null"] || dict[@"posiTion"] == nil) {
            cell.posiTion.text = @"";
        }else{
            cell.posiTion.text = dict[@"posiTion"];
        }
    }else{
        cell.posiTion.text = @"";
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    [cell.headPhotoImageView sd_setImageWithURL:dict[@"headPhoto"]];
  
    if ([dict[@"commentUsername"] isEqualToString:@"null"] || [dict[@"commentUsername"] isEqualToString:@""]) {
        cell.userName.text = dict[@"commentAccount"];
    }else{
    cell.userName.text = dict[@"commentUsername"];
    }
    //  //判断上级
    cell.companyUserName.text = [UsedTool userType:dict[@"userType"] companyName:dict[@"companyName"] userAddress:dict[@"userAddress"]];
    CGSize sizeUserName = [cell.userName sizeThatFits:CGSizeMake(MAXFLOAT, 21)];
    CGSize sizePosition = [cell.posiTion sizeThatFits:CGSizeMake(MAXFLOAT, 21)];
    //名字长度控制
    if (sizePosition.width == 0) {
        if (sizeUserName.width > 170.0f) {
            cell.userNameConstraint.constant = 170.0f;
        }else{
            cell.userNameConstraint.constant = sizeUserName.width;
        }
    }else{
        if ((sizeUserName.width + sizePosition.width) <= 170.0f) {
            cell.userNameConstraint.constant = sizeUserName.width;
            cell.posiTionConstraint.constant = sizePosition.width;
        }else{
            
            if (sizeUserName.width >110.0f) {
                cell.userNameConstraint.constant = 110.0f;
            }else{
                cell.userNameConstraint.constant = sizeUserName.width;
            }
            if (sizePosition.width > 60.0f) {
                cell.posiTionConstraint.constant = 60.0f;
            }else{
                cell.posiTionConstraint.constant = sizePosition.width;
            }
        }
    }

    
    
    NSDate *date = [CustomExcetion dateFromString:dict[@"createTime"]];
    
    cell.timeLabel.text = [CustomExcetion prettyDateWithReference:date];
    
    cell.commentContent.text = dict[@"content"];
    
    //会员图标
    cell.authStateImageView.image = [UsedTool setVipimage:dict[@"vipLevel"]];
    //认证
    cell.isAuthState.hidden = [UsedTool authStateImageViewHidden:dict[@"authState"]];
    

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PinLunCell *cell = [self tableView:self.tableview cellForRowAtIndexPath:indexPath];

        //设置cell自适应高度
    UILabel *descLabel = [[UILabel alloc]init];
    
    descLabel.text = self.projectData[indexPath.row][@"content"];
    descLabel.numberOfLines = 0;
    descLabel.font = [UIFont systemFontOfSize:14];
    CGSize constraint = CGSizeMake(screenW-16, 2000.0f);
    
    CGSize size = [descLabel sizeThatFits:constraint];
    
    self.tableview.height = self.tableview.contentSize.height;
    self.scrollView.contentSize = CGSizeMake( 0, self.tableview.height + self.topTitle.height + self.projectFir.frame.size.height + 100);

    return cell.frame.size.height + size.height-16;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - 请求数据


#pragma mark - 获取更多评论

-(void)sendProjectRequest{

    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[@"page"] = @(page);
    dic[@"projectId"] = self.projectId;
    
    
    [LSHttpTool sendHttpData:@"manyComentProject_app_project.im" params:dic success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        
            if ([dicInfo[@"result"] integerValue] == 1) {
                
                NSArray *aryInff = [NSArray arrayWithArray:[dicInfo objectForKey:@"data"][@"record"]];
                
                for (int i = 0; i<aryInff.count; i++) {
                    [self.projectData addObject:aryInff[i]];
                }
                
                if (aryInff.count == 10) {
                    self.scrollView.mj_footer.hidden = NO;
                }else {
                    self.scrollView.mj_footer.hidden = YES;
                }
                
                
                [self.tableview reloadData];

            }else{
                //设置tableview
                [self setupTableView];
                [self.tableview reloadData];


            }
        
        [self.scrollView.mj_footer endRefreshing];
        
    } failure:^(NSError *error) {

        [self.scrollView.mj_footer endRefreshing];

        [self showSingleIconBubble:@"未搜索到资源"];
  
    }];
}

//收起展开
-(void)downButton:(UIButton *)btn{
    btn.selected = !btn.selected;
    count +=1;
    [self.tableview removeFromSuperview];
    if (count % 2 == 0) {
        self.projectFir.descriptionLabel.numberOfLines = 0;
    }else{
        self.projectFir.descriptionLabel.numberOfLines = 3;
            }
    
    [self setupProjectFir];
  
}

//换算金额
-(NSString *)comperNumber:(NSString *)number
{
    CGFloat num1 = [number floatValue];
    NSString *strNum = @"";
    
    if (num1 >= 100000000) {
        
        strNum = [NSString stringWithFormat:@"%.2f亿元",num1/100000000];
    }else if (num1<100000000 && num1>=10000){
        
        strNum = [NSString stringWithFormat:@"%.2f万元",num1/10000];
    }else{
        
        strNum = [NSString stringWithFormat:@"%.2f元",num1];
    }
    return strNum;
}


@end
